/**
 * @param {number} capacity
 */
 var LRUCache = function(capacity) {
  this.length = capacity;
  this.map = new Map();
};

/** 
* @param {number} key
* @return {number}
*/
LRUCache.prototype.get = function(key) {
  if (this.map.has(key)) {
      const data = this.map.get(key);
      this.map.delete(key);
      this.map.set(key, data);
      return data;
  } else {
      return -1;
  }
};

/** 
* @param {number} key 
* @param {number} value
* @return {void}
*/
LRUCache.prototype.put = function(key, value) {
  if (this.map.has(key)) {
      this.map.delete(key);
  }
  this.map.set(key, value);

  if (this.map.size > this.length) {
      const delKey = this.map.keys().next().value;
      this.map.delete(delKey);
  }
};

/**
* Your LRUCache object will be instantiated and called as such:
* var obj = new LRUCache(capacity)
* var param_1 = obj.get(key)
* obj.put(key,value)
*/